// pages/hongbao/detail.js
const app = getApp();
const TRADIS = require('../../tradis/tradis.js');
import config from '../../utils/config.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIn: 'detail',
    isfetch:false,
    bonus_id:0,
    fee:0,
    userInfo:{},
    isfb:0,
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    this.setData({
      fee:options.fee,
      bonus_id: options.id,
      userInfo:wx.getStorageSync('userInfo'),
    })
    setTimeout(()=>{
      this.setData({ isfetch: true });
    },500)
    wx.showShareMenu({
      withShareTicket: true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    TRADIS.tradis(this);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = app.getShareDefault();
    return {
      title:  shareObj.sharetxt,
      imageUrl: shareObj.imgurl,
      path: '/pages/index/index',
      success: (res) => {
        if (res.shareTickets!=undefined){
          wx.reportAnalytics('isgroup', {
            hasgid: 'have',
          });

        }
        else{
          wx.reportAnalytics('isgroup', {
            hasgid: 'no',
          });
        }
        wx.request({
          url: app.globalData.api + '/bonus/golddouble.html&token=' + wx.getStorageSync('token'),
          method: 'post',
          data: {
            "bonus_id": this.data.bonus_id,
          },
          success: (res) => {
            debugger;
            console.log(res);
            if(res.data.code==0){
              if (res.data.data.fee!=undefined){
                this.setData({
                  isfb: res.data.data.is_double,
                  fee: res.data.data.fee

                })
              }
              else{
                wx.showToast({
                  title: '翻倍失败',
                  icon:'none'
                })
              }
            }
            

          }
        })
      },
      fail: function (res) {
        // 转发失败
        wx.showToast({
          title: '分享失败',
          icon: 'none',
        })
      }
    }
  
  },
  go_continue:function(){
    wx.redirectTo({
      url: '/pages/game/play',
    })

  },
  go_record:function(){
    wx.redirectTo({
      url: '/pages/user/index',
    })
  }
})